#例5-1 
list01 = [1,2,"Python","千峰"]
print("list01[3]:",list01[3])
print("list01[-1]:",list01[-1])

seq[start:end:step]

#例5-2
list01 = [1,2,"Python","千峰"]
print("list01[1:3]:",list01[1:3])
print("list01[:3]:",list01[:3])
print("list01[::2]:",list01[::2])

#例5-3
list01 = ["蒸南瓜","溜茭白","带鱼"]
list02 = ["油泼肉","三鲜丸子"]
print(list01+list02)

#例5-4
list01 = ["蒸南瓜","溜茭白","带鱼"]
sname="油泼肉"
print(list01+list02)

#例5-5
print ("Python "*5)
print(["Python"]*5)
print(("Python",1)*5)

#例5-6
list01-[1,2,3,4,5] 
if 3 in list01: 
print("3在列表1ist01中") 
else: 
print("3不在列表1ist01中")

#例5-7
tuple01=("千锋","教育") 
 if "千锋" notin tuple01: 
 print("'千锋1不在元组tuple01中") 
 else: 
 print ("千锋在元组tuple01中")


#例5-8
sname - "Python" 
print ("字符串长度为",len(sname))
list01-["Python", "C++","Java", "Go"] 
print ("列表长度为",len(list01)) 
tuple01-("Python", "C++", " Java""Go") 
print("元组长度为",len(tuple01))

#例5-9
list01-[1,7,8,4,4,5,6] 
print("列表中的最大元素为:",max(list01))

#例5-10
print("字符'a'的Unicode是:",Ord("a"))
print ("Unicode是97的字符是:",chr(97))


#例5-11
print ('"hello">"happy"的运行结果为:', "hello">"happy")

#例5-12
list01 -["hello", "happy", "python"] 
print("list01中的最大值是:", max(list01))

#例5-13
sname-"Python" 
print("字符串中的最小元素是:" ,min(sname)) 
tuple01-("Python","Hello", "Tuple") 
print("元组中的最小元素是:", min(tuple01))


#例5-14
list01-["hello",123,"Python",123] 
2print("列表中第一次出现元素123的索引为:",list01.index(123))

#例5-15
list01-["hello",123,"Python", 123] 
print("列表中出现123的总次数为:",1ist01.Count(123))


#例5-16
list01 - list () 
list02 - list ("qianfeng") 
1ist03 -list((1,2,3,4,5)) 
list04-list(range (1,5,2)) 
print ("list01为:",1ist01) 
print("list02为:",list02) 
print ("list03为:",list03) 
print("list04为:",list04)
list01为:[]
list02为:['q','i','a','n','f','e','n','g'] 
1ist03为:[1,2,3,4,5] 
list04为:[1,3] 

#例5-17
list02-list("qianfeng") 
print("list02为:",list02) 
sname="".join (list02) 
print("将1ist02合并为字符串:",sname)

#例5-18
food list =["苹果","香蕉","橘子","芒果"] 
for item in food_list: 
print("遍历得到的元素为:",item)

#例5-19
food list=["苹果","香蕉","橘子","芒果"] 
for i in range (len (food list)): 
print(f"索引为1的元素是{food_list[i]}")

#例5-20
food_list =["苹果","香蕉","橘子","芒果"] 
for index,item in enumerate (food_list): 
print(f"索引为(index)的元素是(item)")

#例5-21
list01-[1,2,3,4] 
list01.append (5) 
print (list01)

#例5-22
list01- [1,2,3,4] 
list01.extend([5,6,7])
print(list01)

#例5-23
list01-[1,2,3,4] 
1ist01.insert(1,"插入元素") 
print (list01)

#例5-24
list01-[1,2,3,4] 
list01[1]-5 
print (list01)

#例5-25
list01 -[1,2,3,4] 
list01[1:3]-[9,10]
print (list01)


#例5-26
list01-[1,2,3,4] 
element -list01.pop () 
print (f"删除元素(element),1list01变为(1list01)") 
element -list01.pop (0) 
print (f"删除元素(element),list01变为(1ist01")

#例5-27
list01-[1,2,3,4] 
list01.remove (2) 
print(list01)

#例5-28
list01-[1,2,3,4,5,6,7,8,9,10] 
del list01[2] 
print (list01) 
del list01[1:3] 
print (list01) 
del list01[:] 
print(list01)

#例5-29
age list-[17,16,18,19,16,18] 
age list.sort() 
print(age list)

#例5-30
age_list- [17,16,18,19,16,18]
AN age_list.sort (reverse-True) 
print(age list)

#例5-31
poem = "所谓伊人，在水一方" 
poem_list = list (poem) 
print("将诗句字符串转化为列表:",poem_list) 
poem _list.reverse () 
print("诗句列表反转后变为:",poem_list) 
poem_reverse =""join(poem_list)
print("使用join()方法将列表合并为字符串:",poem_reverse)

#例5-32
age_list -[17,16,18,19,16,18] 
sort list - sorted (age list) 
print("排序后的列表:",sort_list) 
print ("原列表:",age_list)

#例5-33
age_list-[17,16,18,19,16,18] 
sort list-sorted(age list,reverse-True) 
print("排序后的列表:", sort_list)

#例5-34
person hobbies =["游泳","跑步","唱歌"]
friend _hobbies - person_hobbies[:] 
print("朋友的爱好:",friend hobbies)

#例5-35
person hobbies =["游泳","跑步", "唱歌"] 
friend hobbies = person hobbies[:] 
person_hobbies.append("爬山") 
friend_hobbies.append("养花") 
print("此人的爱好:"person_hobbies) 
print("朋友的爱好:", friend_ hobbies)

#例5-36
person_hobbies=["游泳","跑步", "唱歌"]
friend hobbies- person hobbies
print (friend hobbies)

#例5-37
person_hobbies=["游泳","跑步","唱歌"]
friend hobbies-person hobbies
person hobbies.append("爬山") 
friend hobbies.append("养花")
print ("此人的爱好:",person hobbies) 
print("朋友的爱好:", friend hobbies)

#例5-38
square_list-I1 
for item in range (1,11): 
square_list.append (item **2) 
print (square_list)

#例5-39
origin list-[1,4,5,12,32,31,54] 
even_list-I1 
for item in origin list: 
if item %2--O: 
even_list,append(item) 
print (even_list)

#例5-40
origin list- [1,4,5,12,32,31,54] 
even list- [item for itemin origin list if item2-0] 
print(even list)

#例5-41
run 1ist =["0分钟","20分钟","40分钟","60分钟"] 
Swim 1ist =["0米","200米","400米","600米"] 
for index, run in enumerate(run_list): 
print (f"(index+1),frun) ") 
run opt =int(input("请选择您要跑的时长选项:")) 
for index, swim in enumerate (swim_list): 
print (f"{index+1}{swim} ") 
Swim opt =int (input("请选择您要游泳的长度选项:")) 
print (f"制订每日运动计划:跑步{run list run [opt-1]},游泳{iswim 1ist [swim opt-1]}")

#例5-42
run list =["0分钟","20分钟", "40分钟","60分钟"] 
swim list =["0米", "200米" "400米", "600米"] 
calories list-Il 
for i in range (len (run list)): 
for jin range (len (swim list)): 
calories list. append(i*200 +j* 100) 
print ("热量列表:",calories 1ist) 
print(f"运动计划中最多消耗{max(calories list)}热量，最少消耗[min (calories list)]热量")

#例5-43
tuple01 -tuple() 
2 tuple02-tuple ("qianfeng") #创建空元组
tuple03- tuple([1,2,3,4,5]) 
#将字符串转换为元组
4 tuple04- tuple(range (1,5,2)) #将列表转换为元组
5 print("tuple01为:",tuple01)
print ("tuple02为: ",tuple02) 
print ("tuple03: ",tuple03) 
print("tuple04为: ",tuple04)

#例5-44
food tuple=("大米饭","南瓜粥","烤鸭")
for item in food tuple: 
print ("遍历元素为:",item)

#例5-45
products=[("牛奶"，5),("鸡蛋"，20),("香蕉"，10),("杯子"，10)] 
shopping list-Il 
money =float(input("请输入您的购物资金:")) 
while True: 
print ("*"*30) 
print("商品列表如下:") 
for index, product in enumerate (products): 
print(f"{index+1}.商品:{product [0]},价格:{product[1]}") 
print("*"n30) 
option =input("请输入您要购买的商品(退出请键入q):") 
if option.isdigit(): 
option - int (option) 
if O <-option-1 < len (products): 
option product -products [option-1] 
if option product[1] <-money: 
shopping list.append (option product) 
money--option product[1] 
print ("购买成功！") 
else: 
print(f"您的余额不足，余额为:{money}") 
else: 
print ("您选的商品不存在！") 
elif option -"q": 
print("_"*10,"购物清单""_" *10) 
for item in shoppinglist: 
print(f"已购商品:item [0]1,价格:{item [1]}") 
print("您的余额为:",money) 
break 
else: 
print ("您的输入不合法！")
